import {AbstractControl, FormControl, FormGroup} from '@angular/forms';
import set = Reflect.set;

export function phoneValidator(control: AbstractControl): any {
  var myreg = /^(((13[0-9]{1}|(15[0-9]{1})|18[0-9]{1}))+\d{8})$/;
  let valid = myreg.test(control.value);
  console.log('mobile的校验结果是:' + valid);
  return valid ? null : {phone: true};
}

export function equalValidator(group: FormGroup): any {
    let password: FormControl = group.get('password') as FormControl;
    let confirm: FormControl = group.get('confirm') as FormControl;
    let passwordValid: boolean = (password.value === confirm.value);
    console.log('password的校验结果：' + passwordValid);
    return passwordValid ? null : {equal: {msg: '前后密码不一致，请重新输入'}};
}
